﻿using Castle.DynamicProxy;

using PLCS.App.Shared.Extensions;
using PLCS.App.Shared.ViewModels;
using PLCS.Application.Contracts.PLCConfigApp.Dtos;
using PLCS.Client.IService;
using PLCS.Client.IService.ConfigManager;

using System.Threading.Tasks;

namespace PLCS.App.ConfigManager.ViewModels.PLCConfig;

internal class PLCConfigViewModel : NavigationPagedCurdViewModel<PLCConfigDto, PLCConfigEditDto, IPLCConfigService>
{
    private string _plcNo;

    public string PlcNo
    {
        get { return _plcNo; }
        set { SetProperty(ref _plcNo, value); }
    }

    private string _ipAddress;

    public string IpAddress
    {
        get { return _ipAddress; }
        set { SetProperty(ref _ipAddress, value); }
    }

    public PLCConfigViewModel(IPLCConfigService service) : base(service)
    {
        View = "PLC配置";
    }

    public override async Task GetPageData(int pageIndex)
    {
        try
        {
            UpdateLoading(true);
            var res = await _service.GetListBySearchAsync((pageIndex - 1) * PageSize, PageSize, PlcNo, IpAddress);
            TotalCount = (int)res.TotalCount;
            SetPageCount();
            DataGridList = res.Items.ToObservable();
        }
        finally
        {
            UpdateLoading(false);
        }
    }
}